#ifndef __SV2_CAMERAIO__
#define __SV2_CAMERAIO__

#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <queue>
#include <stack>
#include <thread>


namespace sv2 {


enum class CameraType {NONE, WEBCAM, V4L2CAM, MIPI, RTSP, VIDEO, G1, Q10, GX40, SU17};


class Camera {
public:
  Camera(CameraType type=CameraType::NONE, int id=0);
  ~Camera();
  void open(CameraType type=CameraType::V4L2CAM, int id=0);
  bool read(cv::Mat& image);
  void release();
  
  int getW();
  int getH();
  int getFps();
  std::string getIp();
  int getPort();
  double getBrightness();
  double getContrast();
  double getSaturation();
  double getHue();
  double getExposure();
  std::string getFourcc();
  bool isRunning();
  void setFourcc(std::string fourcc);
  void setWH(int width, int height);
  void setFps(int fps);
  void setIp(std::string ip);
  void setRtspUrl(std::string rtsp_url);
  void setVideoPath(std::string video_path);
  void setPort(int port);
  void setBrightness(double brightness);
  void setContrast(double contrast);
  void setSaturation(double saturation);
  void setHue(double hue);
  void setExposure(double exposure);
protected:
  void openImpl();
  void _run();

  bool _is_running;
  bool _is_updated;
  std::thread _tt;
  cv::VideoCapture _cap;
  cv::Mat _frame;
  CameraType _type;
  int _camera_id;

  int _width;
  int _height;
  int _fps;
  std::string _ip;
  std::string _rtsp_url;
  std::string _video_path;
  int _port;
  double _brightness;
  double _contrast;
  double _saturation;
  double _hue;
  double _exposure;
  std::string _fourcc;
};


}
#endif
